//
//  MyInformationTableViewCell.m
//  BaseFrame
//
//  Created by 吕金状 on 2017/9/5.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "MyInformationTableViewCell.h"

@interface MyInformationTableViewCell ()<UITextFieldDelegate>

Strong UIImageView *titleImageView;
Strong UILabel *titleLabel;
Strong UITextField *textField;
Strong UIView *lineView;

@end

@implementation MyInformationTableViewCell

- (id)initWithCellIdentifier:(NSString *)cellID{
    self = [super initWithCellIdentifier:cellID];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        _titleImageView = [UIImageView new];
        _titleImageView.contentMode = UIViewContentModeScaleAspectFit;
        _titleImageView.image = [UIImage imageNamed:@""];
        
        _titleLabel  = [[UILabel alloc]init];
        _titleLabel.font = DEF_FontSize_14;
        _titleLabel.textColor = getColor(textColor);
        
        _textField  = [[UITextField alloc]init];
        _textField.font = DEF_FontSize_14;
        _textField.textColor = getColor(textColor);
        _textField.delegate = self;
        
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = getColor(dividerColor);
        
        [self.contentView sd_addSubviews:@[_titleLabel , _textField , _titleImageView,_lineView]];
        
    }
    return self;
}

- (void)layoutFrame{
    __weak __typeof(self)weakSelf = self;
    [self.titleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(15 / WIDTH_5S_SCALE);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleImageView.mas_right).offset(5 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
//        make.width.mas_equalTo();
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.titleLabel.mas_right).offset(5 / WIDTH_5S_SCALE);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(0);
        make.width.mas_equalTo(200 / WIDTH_5S_SCALE);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).offset(10 / WIDTH_5S_SCALE);
        make.right.equalTo(weakSelf).offset(-10 / WIDTH_5S_SCALE);
        make.height.mas_equalTo(0.5);
        make.bottom.equalTo(weakSelf);
    }];
    
}

- (void)setModel:(NSDictionary *)model{
    _model = model;
    self.textField.userInteractionEnabled = self.state;
    self.titleImageView.image = [UIImage imageNamed:model[@"image"]];
    self.titleLabel.text = model[@"title"];
    if ([model[@"text"] isEqualToString:@"未设置"] || [model[@"text"] isEqualToString:@""]) {
        self.textField.placeholder = @"未设置";
    }else{
        self.textField.text = model[@"text"];
    }
    [self layoutFrame];
}


#pragma mark - delete

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (_getTextField) {
        _getTextField(textField.text);
    }
}

@end
